package be.nvlooy.moviereminder.common;

import java.io.Serializable;

import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(value="session", proxyMode = ScopedProxyMode.INTERFACES)
public class SessionMessageImpl implements SessionMessage, Serializable {

	private static final long serialVersionUID = 1L;

	private String message;
	
	private MessageType messageType;
	
	
	public SessionMessageImpl() {
		message = null;
	}
	
	public void setMessage(String message) {
		setMessage(message, MessageType.INFO);
	}
	
	public void setMessage(String message, MessageType msgType) {
		this.message = message;
		this.messageType = msgType;
	}
	
	public String getMessage() {
		if(message == null)
			return null;
		
		String tempMsg = new String(message);
		// remove message so it will only display during one request!
		message = null;
		return tempMsg;
	}
	
	public String getMessageTypeParameter() {
		return messageType.getParameter();
	}

}
